#!/bin/bash

# 获取系统信息
get_system_info() {
    echo -e "\n\e[1;34m🌍 系统探针 v1.0\e[0m"
    
    # 基础信息
    local country=$(curl -s --connect-timeout 2 ipinfo.io/country || echo "Unknown")
	local iipv4=$(curl -s --connect-timeout 2 ipinfo.io/ip || echo "Unknown")
	local iipv6=$(curl -s --max-time 1 https://v6.ipinfo.io/ip || echo "Unknown")
    local os_info=$(grep PRETTY_NAME /etc/os-release | cut -d '"' -f2)
    local cpu_arch=$(uname -m)
    local nic=$(ip route show default | awk '/default/ {print $5}')
    
    echo -e "\n\e[1;36m💻 硬件信息\e[0m"
    echo -e "  🖥️ 操作系统 : \e[32m$os_info\e[0m"
    echo -e "  🧠 CPU架构  : \e[33m$cpu_arch\e[0m"
    echo -e "  🌐 默认网卡 : \e[35m$nic\e[0m"

    # 网络信息
    local ipv4=$(ip -4 addr show $nic | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
    local ipv6=$(ip -6 addr show $nic | grep -oP '(?<=inet6\s)[\da-f:]+')
    
    echo -e "\n\e[1;36m📡 网络信息\e[0m"
    echo -e "  🚀 公网归属 : \e[33m$country\e[0m"
    echo -e "  🏠 内网IPv4 : \e[32m$ipv4\e[0m"
    [ -n "$ipv6" ] && echo -e "  🌌 内网IPv6 : \e[36m$ipv6\e[0m"
    echo -e "  🌏 公网IPv4 : \e[32m$iipv4\e[0m"
    [ -n "$ipv6" ] && echo -e "  🌙 公网IPv6 : \e[36m$iipv6\e[0m"
	
    # 运行状态
    local uptime=$(uptime -p | sed 's/up //;s/ days/天/;s/ hours/小时/')
    local mem_usage=$(free -m | awk '/Mem/ {printf "%.1f%%", $3/$2*100}')
    
    echo -e "\n\e[1;36m⏱️ 运行状态\e[0m"
    echo -e "  ⏳ 运行时长 : \e[35m$uptime\e[0m"
    echo -e "  💾 内存占用 : \e[33m$mem_usage\e[0m"
}

# 执行主函数
get_system_info
echo -e "\n\e[1;32m✅ 信息获取完成！！\e[0m\n"